Create
准备将程式连接到 KINGSTAR 子系统。
语法
KsError Create(
int Instance,
int IdealProcessor
);
参数
Instance:在有多主站套件的情况下选择想要使用的 KINGSTAR Runtime 实例。若没有此套件,请将其设定为零 (0);若有此套件,则有效的实例应为 0 <= instance <= 63。此实例可依照您的需要而设,例如:您有三个实例并想使用第三个,则将之设为二(2)。
IdealProcessor:设定 KINGSTAR 子系统运作的核心。子系统的所有执行绪将在给定的处理器上运作。核心零固定分配给 Windows。您可根据您的设定将其他核心分配给子系统。预设情况下,IdealProcessor 设定为零,表示 KINGSTAR 将使用实例配置表中所配置的处理器(KINGSTAR 控制台 > Runtime 设定 > 一般设定)。若该表中缺少给定实例的设定,则子系统可在 RTX64 可用的任何核心上运作。若您将 IdealProcessor 设定为其他数字,例如二,则子系统将使用核心二。
回传值
如果此函式执行成功,会回传 errNoError
,否则会传回错误码。如需更多有关错误码的资讯,请参阅 KsError 清单。
备注
- 此函式永远需第一个呼叫,若 Create 未被呼叫,所有函式将回到
errWrongEnvironment
。 - 多实例代表有多个
ksRuntime.rtss
同时运行且控制不同的网路卡,若有 多主站套件,可使用数个 Create 来创建多个实例,例如,有三个 Create 函式,则这些函式可各自使用实例零、一和二;若无多主站套件,使用多个 Create 仅能创建一个实例,也就是实例零。多个应用程式可连结至一个KINGSTAR Runtime,但一个应用程式无法连到多个 Runtime。 - 一个 KINGSTAR Runtime = 一个
ksRuntime.rtss
。
范例
复制
//////////////////////////////////////////////////////////////////
//
// This code snippet demonstrates a basic flow of how to link to
// KINGSTAR subsystem and use the APIs to configure subsystem and
// control the EtherCAT network and motion devices.
//
//////////////////////////////////////////////////////////////////
KsError nRet = errNoError;
KsCommandStatus Command = { 0 };
SubsystemStatus Subsystem = { ecatOffline, ecatOffline, 0, 0, 0, {ecatOffline}, {ecatOffline}, {axisOffline} };
// Link to the KINGSTAR subsystem.
// If the KINGSTAR subsystem does not exist, it would create a new KINGSTAR subsystem.
// You have to call this API first before you use other KINGSTAR functions.
nRet = Create(0, 0);
// Check if the subsystem is started.
// A new KINGSTAR subsystem is not started by default.
nRet = GetStatus(&Subsystem, NULL);
if (Subsystem.State == ecatOP)
{
RtPrintf("Subsystem already started: %x\n", nRet);
}
else if (nRet == errNoError && Subsystem.State == ecatOffline)
{
// When the subsystem state is ecatOffline, you can use below APIs to configure settings:
//
// Subsystem Configuration APIs
// Axis Variable APIs
// AddModuleConfiguration()
// RemoveModuleConfiguration()
// SetConfigurationAxseCount()
// SetConfigurationIoCount()
//
// If you just want to use the default setting, skip this part and start the subsystem.
// Start the subsystem. It would change the subsystem state to ecatOP.
// This function is asynchronous so the network is not started yet when it returns.
// Use WaitForCommand() for synchronization.
Command = WaitForCommand(30, TRUE, Start());
}
// Now the subsystem state is ecatOP, you can use below APIs to control the subsystem and devices:
//
// Subsystem Control
// Slave Control
// Axis Control
// IO Control
// Heartbeat
// COM API
// Motion API
//
// You can also change the subsystem state or slave state.
// Please check "Usable EtherCAT states" section and the API pages to find out
// which functions you can use in different states.
// Stop the EtherCAT network before destroying KINGSTAR Subsystem or before re-configuration.
Command = WaitForCommand(5, FALSE, Stop());
if (Command.Error)
{
RtPrintf("Stop Failed: %d\n", Command.ErrorId);
}
// Terminates the KINGSTAR Subsystem if there is no other application connected to it.
nRet = Destroy();
if (nRet != errNoError)
{
RtPrintf("Destroy Failed: %x\n", nRet);
}
使用需求
RT | Win32 | |
---|---|---|
最低支援版本 | 4.0 | 4.0 |
标头档 | ksapi.h | ksapi.h |
程式库 | KsApi_Rtss.lib | KsApi.lib |
参见